package edu.auctionmart

import static org.junit.Assert.*
import org.junit.*
import org.joda.time.DateTime

class FeedbackIntegrationTests {

   void testFeedback() {
	   User leftFor = new User(username: "Russell", userRealName: "administrator", passwd: "Testinga4b", email: "brian@maine.edu")
	   leftFor.save()
	   
	   User leftBy =  new User(username: "Brian", userRealName: "administrator", passwd: "Testinga4b", email: "brian@maine.edu")
	   leftBy.save()
	   
	   Item item = new Item(name: "Movie", description: "Some movie", category: ItemCategory.Electronics, quantity: 1)
	   item.save()
	   
	   DateTime startTime = new DateTime(2012, 2, 12, 0, 0, 0)
	   DateTime endTime = new DateTime(2012, 2, 15, 0, 0, 0)
	   
	   Auction auction = new Auction(auctionTitle: "Title", startBid: 0.01, seller: leftFor, item: item, startTime: startTime, endTime: endTime, status: AuctionStatus.OnGoing)
	   auction.save()
	   
	   Feedback feedback = new Feedback(leftFor: leftFor, leftBy: leftBy, auction: auction)   
	   feedback.validate()
	   feedback.save()
	   
	   //Can't save if leftFor and leftBy are the same
	   Feedback feedback2 = new Feedback(leftFor: leftFor, leftBy: leftFor, auction: auction)
	   feedback2.save()
	   
	   def foundFeedback = Feedback.get(feedback.id)
	   assertNotNull(foundFeedback)
	   
	   def notFoundFeedback = Feedback.get(feedback2.id)
	   assertNull(notFoundFeedback)
	   
   }
}